

//5秒倒计时
function invokeSettime(obj){
    var countdown=5;
    settime(obj);
    function settime(obj) {
        if (countdown == 0) {
            window.location.href='../static/index.html';
            return;
        } else {
            $(obj).html(" 注册成功 "+ countdown + "s 自动跳转至首页页面");
            countdown--;
        }
        setTimeout(function() {
                settime(obj) }
            ,1000)
    }
}

// 封装ajax
function $ajax(data){
    $.ajax({
        type: "POST",
        url: "/mobile/gateway.action",
        data: data,
        dataType: "json",
        contentType: "application/json",
        async: true,
        success: function (result) {
            return value = result;
           // return localStorage.setItem("publicKey",result.publicKey);
        }
    })
    //     .done(function (result) {
    //     return value=result;
    // });
}

//分段加密
function fenduanjiami(publicKey,str, num) {
    if (str == null || str == undefined) return null;
    if (!(/^[0-9]*[1-9][0-9]*$/.test(num))) return null;
    var array = new Array();
    var len = str.length;
    var encrypt = new JSEncrypt();
    encrypt.setPublicKey(publicKey);
    for (var i = 0; i < (len / num); i++) {
        if ((i + 1) * num > len) {
            array.push(encrypt.encrypt(str.substring(i * num, len)));
        } else {
            array.push(encrypt.encrypt(str.substring(i * num, (i + 1) * num)));
        }
    }
    return array;
}
// $(function() {
//     $("#RSABtn").click(function() {
//         var publicKey = $("#pbc").val();
//         var pbcMsg = $("#pbcMsg").val()
//         var jmMsg = fenduanjiami(publicKey,pbcMsg,58)
//         $("#jmMsg").val(jmMsg)
//     })
// })
//身份证照片大小
function filefujianChange(target) {
    var fileSize = 0;
    if (!target.files) {
        var filePath = target.value;
        var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
        var file = fileSystem.GetFile (filePath);
        fileSize = file.Size;
    } else {
        fileSize = target.files[0].size;
    }
    var size = fileSize / 1024;
    if(size>2000){
        alert("附件不能大于2M");
        target.value="";
        return
    }
    var name=target.value;
    var fileName = name.substring(name.lastIndexOf(".")+1).toLowerCase();
    if(fileName !="jpg" && fileName !="jpeg" && fileName !="pdf" && fileName !="png" && fileName !="dwg" && fileName !="gif" ){
        alert("请选择图片格式文件上传(jpg,png,gif,dwg,pdf,gif等)！");
        target.value="";
        return
    }
}

//获取验证码倒计时
function codeSettime(obj){
    var countdown=60;
    settime(obj);
    function settime(obj) {
        if (countdown == 0) {
            $(obj).attr("disabled",false);
            $(obj).css("backgroundColor","#c8f0ff");
            $(obj).val("获取验证码");
            countdown = 60;
            return;
        } else {
            $(obj).attr("disabled",true);
            $(obj).val("(" + countdown + ") s 重新发送");
            $(obj).css("backgroundColor","#ccc");
            countdown--;
        }
        setTimeout(function() {
                settime(obj) }
            ,1000)
    }
}

